package com.chuangshixinchen.enterprise.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chuangshixinchen.enterprise.common.JwtUtils;
import com.chuangshixinchen.enterprise.common.Result;
import com.chuangshixinchen.enterprise.common.StatusCode;
import com.chuangshixinchen.enterprise.entity.Tb_declaration_flow;
import com.chuangshixinchen.enterprise.entity.Tb_user;
import com.chuangshixinchen.enterprise.service.ITb_declaration_flowService;
import com.chuangshixinchen.enterprise.service.ITb_userService;
import com.chuangshixinchen.enterprise.vo.req.DeclarationFlowReqPageVo;
import com.chuangshixinchen.enterprise.vo.req.UserChangePwdVo;
import com.chuangshixinchen.enterprise.vo.req.UserLoginVo;
import com.chuangshixinchen.enterprise.vo.req.UserReqPageVo;
import com.chuangshixinchen.enterprise.vo.res.DeclarationFlowResVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@Api(value = "流水模块", tags = "流水模块")
@RequestMapping("/declaration")
public class DeclarationController {

    @Autowired
    private ITb_declaration_flowService declarationFlowService;

    @ApiOperation(value = "查询", notes = "根据token查询用户详情")
    @GetMapping(value = "/info/{id}")
    @ResponseBody
    public Result<Tb_declaration_flow> userInfo(@RequestHeader("Authorization") String token,@PathVariable(value = "id") Long id) {
        if (!JwtUtils.checkToken(token)){
            return new Result<Tb_declaration_flow>(false, StatusCode.AUTHORIZATION_ERROR,"授权失败！");
        }
        Result<Tb_declaration_flow> result = declarationFlowService.getInfo(id);
        return result;
    }

    @ApiOperation(value = "查询", notes = "分页查询用户")
    @PostMapping(value = "/page")
    @ResponseBody
    public Result<Page<DeclarationFlowResVo>> page(@RequestHeader("Authorization") String token, @RequestBody DeclarationFlowReqPageVo vo) {
        if (!JwtUtils.checkToken(token)){
            return new Result<Page<DeclarationFlowResVo>>(false, StatusCode.AUTHORIZATION_ERROR,"授权失败！");
        }
        Result<Page<DeclarationFlowResVo>> result = declarationFlowService.listPage(vo);
        return result;
    }

    @ApiOperation(value = "添加", notes = "新增记录提交，并上传附件")
    @PostMapping(value = "/save")
    @ResponseBody
    public Result save(@RequestHeader("Authorization") String token, MultipartFile deFile, MultipartFile prFile, Tb_declaration_flow declarationFlow) {
        if (!JwtUtils.checkToken(token)){
            return new Result<Page<Tb_user>>(false, StatusCode.AUTHORIZATION_ERROR,"授权失败！");
        }
        Result result = declarationFlowService.saveInfo(deFile,prFile,declarationFlowService,declarationFlow);
        return result;
    }



    @ApiOperation(value = "删除", notes = "根据Id删除信息")
    @DeleteMapping(value = "/removeById/{ids}")
    @ResponseBody
    public Result save(@PathVariable(value = "ids") String ids, @RequestHeader("Authorization") String token) {
        if (!JwtUtils.checkToken(token)) {
            return new Result(false, StatusCode.AUTHORIZATION_ERROR, "授权失败！");
        }
        Result result = declarationFlowService.removeInfo(ids);
        return result;
    }
}
